using Gx.Common;
using Gx.Dal;
using Gx.Dal.Manage;
using Gx.Model;
using Gx.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;


namespace Gx.Bll.Manage
{
    public class LKGoodsSpecBll
    {
        public List<LKGoodsSpec> GetLKGoodsSpecs()
        {
            BaseDal<LKGoodsSpec> dal = new BaseDal<LKGoodsSpec>();
            return dal.GetAll().ToList();
        }

        /// <summary>
        /// 新增商品规格
        /// </summary>
        /// <param name="lKGoodsSpec"></param>
        /// <returns></returns>
        public ReturnModel AddLKGoodsSpec(LKGoodsSpec lKGoodsSpec)
        {
            LKGoodsSpecDal dal = new LKGoodsSpecDal();

            var any = dal.AnyGoodsSpecName(lKGoodsSpec.SpecName);
            if (any)
            {
                return new ReturnModel { Success = false, Msg = "规格名称已存在" };
            }


            lKGoodsSpec.CreateTime = DateTime.Now;
            lKGoodsSpec.CreateUserId = LoginHelper.GetUserId();
            lKGoodsSpec.CreateUser = LoginHelper.UserName();
            var result= dal.Insert(lKGoodsSpec);
            return new ReturnModel { Success = result, Msg = result ? "新增成功" : "新增失败" };
        }

        /// <summary>
        /// 编辑商品规格
        /// </summary>
        /// <param name="lKGoodsSpec"></param>
        /// <returns></returns>
        public bool EditLKGoodsSpec(LKGoodsSpec lKGoodsSpec)
        {
            BaseDal<LKGoodsSpec> dal = new BaseDal<LKGoodsSpec>();
            var cus = dal.Get(lKGoodsSpec.Id);
            if (cus == null)
            {
                return false;
            }
            lKGoodsSpec.CreateTime = cus.CreateTime;
            lKGoodsSpec.CreateUserId = cus.CreateUserId;
            lKGoodsSpec.CreateUser = cus.CreateUser;
            return dal.Update(lKGoodsSpec);
        }

        /// <summary>
        /// 删除客户等级
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteLKGoodsSpec(int id)
        {
            BaseDal<LKGoodsSpec> dal = new BaseDal<LKGoodsSpec>();
            return dal.DeleteById(id);
        }
    }
}

